import { createApp } from 'vue'
import App from './App.vue'
import { setupVab } from '~/library'
import { setupI18n } from '@/i18n'
import { setupStore } from '@/store'
import { setupRouter } from '@/router'
import { useUserStore } from './store/modules/user'
import watermark from './utils/watermark'
import router from '@/router'
import { pwa } from './config'

const app = createApp(App)
const userStore = useUserStore()
const { name } = storeToRefs(userStore)

router.afterEach((item) => {
  if (
    item.name !== 'Login' &&
    item.name !== 'Callback' &&
    item.name !== '403' &&
    item.name !== '404'
  ) {
    //@ts-ignore
    watermark.set(name._object.name)
  } else {
    //@ts-ignore
    watermark.set('')
  }
})
// 正式环境清除所有console.log
if (process.env.NODE_ENV === 'production') {
  if (window) {
    //重写console方法
    window.console.log = function () {}
  }
}
/**
 * @description 生产环境启用组件初始化，编译，渲染和补丁性能跟踪。仅在开发模式和支持 Performance.mark API的浏览器中工作。
 */
//if (process.env.NODE_ENV === 'development') app.config.performance = true

if (pwa) require('./registerServiceWorker')

setupVab(app)
setupI18n(app)
setupStore(app)
setupRouter(app)
  .isReady()
  .then(() => app.mount('#app'))
